package com.hepinghospital.user.adapter

import android.annotation.SuppressLint
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.TextUtils
import android.text.style.ForegroundColorSpan
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.hepinghospital.user.R
import com.rest.response.NursingOrderResponse

/**
 * @Description: 我的护理 适配器
 * @Author: lzp
 * @CreateDate: 2022/3/9 15:01
 * @UpdateRemark: 更新说明
 */
class NursingOrderAdapter(data: MutableList<NursingOrderResponse.NursingOrder>) : BaseQuickAdapter<NursingOrderResponse.NursingOrder, BaseViewHolder>(R.layout.item_nursing_appoint_order, data) {

    @SuppressLint("SetTextI18n")
    override fun convert(holder: BaseViewHolder, item: NursingOrderResponse.NursingOrder) {
        holder.setText(R.id.tv_appoint_name, "预约人：" + item.patientName)
        holder.setText(R.id.tv_address, "地址：" + item.adress)
        holder.setText(R.id.tv_time, "时间：" + item.appointmentTime)
        holder.setGone(R.id.tv_name, TextUtils.isEmpty(item.nurseName))

        //预约状态订单状态 0待支付 1待审核:待分配 2待审核:未接单 3已预约 4已取消 5已完成
        when (item.appointmentStatus) {
            0 -> {
                holder.setText(R.id.tv_status, "待支付")
                    .setTextColor(R.id.tv_status, ContextCompat.getColor(context, R.color.fff54c4c))
                holder.setText(R.id.tv_name, "暂未分配护士，请等待")
                holder.setGone(R.id.tv_name, false)
                holder.setGone(R.id.tv_work, true)
                holder.setText(R.id.tv_money, "￥${item.orderAmount.toFloat() / 100}")
                    .setGone(R.id.tv_money, false)
                holder.setGone(R.id.tv_consumeMaterials, true)
                holder.setGone(R.id.tv_reason, true)
                holder.setGone(R.id.tv_pay_tip, false)
                val spannable = SpannableStringBuilder("请在${item.leftMin}分钟内完成支付")
                spannable.setSpan(ForegroundColorSpan(ContextCompat.getColor(context, R.color.color_F2A37D)), 2, spannable.length - 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
                holder.setText(R.id.tv_pay_tip, spannable)
                holder.setGone(R.id.tv_pay, false)
                holder.setGone(R.id.tv_cancel, false)
                holder.setGone(R.id.tv_evaluate, true)
            }
            1, 2 -> {
                holder.setText(R.id.tv_status, "待审核")
                    .setTextColor(R.id.tv_status, ContextCompat.getColor(context, R.color.fff54c4c))
                holder.setText(R.id.tv_name, "暂未分配护士，请等待")
                holder.setGone(R.id.tv_name, false)
                holder.setGone(R.id.tv_money, true)
                holder.setGone(R.id.tv_work, true)
                holder.setGone(R.id.tv_consumeMaterials, true)
                holder.setGone(R.id.tv_reason, true)
                holder.setGone(R.id.tv_pay_tip, true)
                //护士是否出发 1为出发不能取消订单
                holder.setGone(R.id.tv_cancel, item.isSetOut == 1)
                holder.setGone(R.id.tv_pay, true)
                holder.setGone(R.id.tv_evaluate, true)
            }
            3 -> {
                holder.setText(R.id.tv_status, "已预约")
                    .setTextColor(R.id.tv_status, ContextCompat.getColor(context, R.color.mainBlue))
                holder.setText(R.id.tv_name, item.nurseName)
                holder.setGone(R.id.tv_work, false)
                holder.setGone(R.id.tv_money, true)
                holder.setGone(R.id.tv_pay_tip, true)
                holder.setGone(R.id.tv_reason, true)
                holder.setGone(R.id.tv_pay, true)
                //护士是否出发 1为出发不能取消订单
                holder.setGone(R.id.tv_cancel, item.isSetOut == 1)
                holder.setGone(R.id.tv_evaluate, true)
                if (item.consumeMaterials != null) {
                    for (bean in item.consumeMaterials) {
                        if (bean.orderStatus == 10) {
                            holder.setGone(R.id.tv_consumeMaterials, false)
                            break
                        } else {
                            holder.setGone(R.id.tv_consumeMaterials, true)
                        }
                    }
                }
            }
            4 -> {
                holder.setText(R.id.tv_status, "已取消")
                    .setTextColor(R.id.tv_status, ContextCompat.getColor(context, R.color.ff999999))
                holder.setText(R.id.tv_name, item.nurseName)
                holder.setGone(R.id.tv_work, false)
                holder.setGone(R.id.tv_money, true)
                holder.setGone(R.id.tv_pay_tip, true)
                holder.setGone(R.id.tv_consumeMaterials, true)
                holder.setGone(R.id.tv_reason, false)
                holder.setGone(R.id.tv_pay, true)
                holder.setGone(R.id.tv_cancel, true)
                holder.setGone(R.id.tv_evaluate, true)
                if (!TextUtils.isEmpty(item.cancelReason)) {
                    holder.setText(R.id.tv_reason, "取消原因：${item.cancelReason}")
                }
            }
            5 -> {
                holder.setText(R.id.tv_status, "已完成")
                    .setTextColor(R.id.tv_status, ContextCompat.getColor(context, R.color.color_A8D2CB))
                holder.setText(R.id.tv_name, item.nurseName)
                holder.setGone(R.id.tv_work, false)
                holder.setGone(R.id.tv_money, true)
                holder.setGone(R.id.tv_pay_tip, true)
                holder.setGone(R.id.tv_consumeMaterials, true)
                holder.setGone(R.id.tv_reason, true)
                holder.setGone(R.id.tv_pay, true)
                holder.setGone(R.id.tv_cancel, true)
                holder.setGone(R.id.tv_evaluate, false)
            }
            else -> {
                holder.setText(R.id.tv_status, "已评价")
                    .setTextColor(R.id.tv_status, ContextCompat.getColor(context, R.color.color_A8D2CB))
                holder.setText(R.id.tv_name, item.nurseName)
                holder.setGone(R.id.tv_work, false)
                holder.setGone(R.id.tv_money, true)
                holder.setGone(R.id.tv_pay_tip, true)
                holder.setGone(R.id.tv_consumeMaterials, true)
                holder.setGone(R.id.tv_reason, true)
                holder.setGone(R.id.tv_pay, true)
                holder.setGone(R.id.tv_cancel, true)
                holder.setGone(R.id.tv_evaluate, true)
            }
        }
        if (item.orderStatus == 50) {
            holder.setText(R.id.tv_status, "退款中")
            holder.setGone(R.id.tv_cancel, true)
        } else if (item.orderStatus == 900) {
            holder.setText(R.id.tv_status, "订单异常")
            holder.setGone(R.id.tv_cancel, true)
        }
    }
}